<?php
/*
Plugin Name: Filter-This!
Plugin URI: http://www.kreativplugin.com/filter-this/
Description: Adds a fast and configurable post thumbnails filter on a page 
Author: Andrei O.
Version: 0.1
Author URI: http://www.kreativplugin.com
*/

//admin settings menu
function filter_this_menu() {
  	
	add_submenu_page( 'options-general.php', 'Filter This', 'Filter This', 'manage_options', 'filter-this', 'filter_this_settings' );

	add_action( 'admin_init', 'filter_this_save' );
	
}

add_action('admin_menu', 'filter_this_menu');

function filter_this_save() {

	register_setting( 'filter-this-group', 'jquery' );
	
	register_setting( 'filter-this-group', 'filter-by-type' );
	
	register_setting( 'filter-this-group', 'filter-by-sort' );	
	
	register_setting( 'filter-this-group', 'filter-by-search' );
	
	register_setting( 'filter-this-group', 'filter-by-items' );
	
	register_setting( 'filter-this-group', 'filter-layout' );

}

function filter_this_settings() { ?>
	<div class="wrap">
	<div id="icon-options-general" class="icon32"><br></div>
	<h2>Filter This Settings</h2>

	<?php echo "Here it will be displayed the <b>Filter This!</b> seetings"; ?>
	
	<form method="post" action="options.php">
		
		<?php settings_fields( 'filter-this-group' ); ?>
		
		<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
	
	</form>
	</div>
	
	<?php
}

function filter_this() {
		
		?>
		
		<div id="filter-category">
	
		Category
		
		<ul id="filter">
	
			<?php 	
			
				ob_start();
				
				wp_list_categories('title_li=&exclude=1,25,26,28');
				
				$html = ob_get_clean();
				
				echo str_replace(home_url().'/category/','/#',$html);
				
			?>
		
		</ul>
		
		</div>
		
		<div id="filter-reset">
	
		Filter
		
		<ul id="filter">
		
			<li><a href="#reset">Reset</a></li>
			
			<li><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.kreativtheme.com&amp;send=false&amp;layout=standard&amp;width=56&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=24" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:56px; height:24px;" allowTransparency="true"></iframe></li>
			
			<li><a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-via="KreativTheme">Tweet</a></li>
			
			<li><g:plusone size="tall" annotation="none"></g:plusone></li>
			
		</ul>
		
	</div>
	
	<?php query_posts( 'cat=25&posts_per_page=200');
	 
		if ( have_posts() ) : while ( have_posts() ) : the_post();?>

		<li class="reset <?php $terms = get_the_terms( $post->id, 'category'); if ($terms) foreach( $terms as $term ) { print $term->slug . ' '; unset($term); }; $tags = wp_get_post_tags($post->ID); if ($tags) foreach($tags as $tag) { print $tag->slug . ' '; unset($tag); }?>">
			
			<div class="center">
				
				<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">				 
				
				<?php the_title(); ?>
				
				<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>

				<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $image[0]; ?>&h=121&w=215&zc=1&a=t" alt="<?php the_title(); ?>" width="215" height="121" />
							
				</a>
				
			</div>
			
			<div class="cart">
				
				<a href="<?php echo get_option('home'); ?>/go/<?php print $slug = basename(get_permalink()); ?>" target="_blank" title="Download <?php the_title(); ?> Theme">Download Theme</a>
			
			</div>
			
		</li>

		<?php endwhile; endif; ?>
		
    </ul>
	
	<?php wp_reset_query();
		
}

add_shortcode('filter-this','filter_this');